package cola.machine.game.myblocks.model.AABB;

import com.dozenx.util.MathUtil;
import javafx.beans.NamedArg;
import javafx.geometry.Bounds;

public class SimpleAABB {
    float posMinX,posMinY,posMinZ,posMaxX,posMaxY,posMaxZ;

    public float minX, minY, minZ, maxX, maxY, maxZ;

    public float getMinX() {
        return minX;
    }

    public void setMinX(float minX) {
        this.minX = minX;
    }

    public float getMinY() {
        return minY;
    }

    public void setMinY(float minY) {
        this.minY = minY;
    }

    public float getMinZ() {
        return minZ;
    }

    public void setMinZ(float minZ) {
        this.minZ = minZ;
    }

    public float getMaxX() {
        return maxX;
    }

    public void setMaxX(float maxX) {
        this.maxX = maxX;
    }

    public float getMaxY() {
        return maxY;
    }

    public void setMaxY(float maxY) {
        this.maxY = maxY;
    }

    public float getMaxZ() {
        return maxZ;
    }

    public void setMaxZ(float maxZ) {
        this.maxZ = maxZ;
    }

    public void setAABB(float minX, float minY, float minZ,
                        float maxX, float maxY, float maxZ) {
        this.minX = minX;
        this.minY = minY;
        this.minZ = minZ;
        this.maxX = maxX;
        this.maxY = maxY;
        this.maxZ = maxZ;
    }


   public void  setAABBSPosition(float posX,float posY,float posZ){
        this.posMinX = posX+minX;
       this.posMinY = posY+minY;
       this.posMinZ = posZ+minZ;


       this.posMaxX = posX+maxX;
       this.posMaxY = posY+maxY;
       this.posMaxZ = posZ+maxZ;
    }

    //碰撞检测
    public boolean overlaps(SimpleAABB aabb2) {
//        return !(maxX < aabb2.minX || minX > aabb2.maxX)
//                && !(maxY < aabb2.minY || minY > aabb2.maxY)
//                && !(maxZ < aabb2.minZ || minZ > aabb2.maxZ);

        return MathUtil.testCubeXiangjiao(aabb2.minX, aabb2.minY, aabb2.minZ, aabb2.maxX - aabb2.minX, aabb2.maxY - aabb2.minY, aabb2.maxZ - aabb2.minZ,
                this.minX, this.minY
                , this.minZ, this.maxX - this.minX, this.maxY - this.minY, this.maxZ - this.minZ
        );
    }

    public void reCaculate() {

    }


    /**
     * {@inheritDoc}
     */
     public boolean intersects(float x, float y, float z,
                               float w, float h, float d) {
        if (isEmpty() || w < 0 || h < 0 || d < 0) return false;
        return (x + w >= getMinX() &&
                y + h >= getMinY() &&
                z + d >= getMinZ() &&
                x <= getMaxX() &&
                y <= getMaxY() &&
                z <= getMaxZ());
    }
    /**
     * {@inheritDoc}
     */
   public boolean intersects(SimpleAABB b) {
        if ((b == null) || b.isEmpty()) return false;
        return intersects(b.getMinX(), b.getMinY(), b.getMinZ(),
                b.getWidth(), b.getHeight(), b.getDepth());
    }
    public boolean isEmpty() {
        return getMaxX() < getMinX() || getMaxY() < getMinY() || getMaxZ() < getMinZ();
    }

    /**
     * Creates a new instance of 3D {@code BoundingBox}.
     * @param minX the X coordinate of the upper-left corner
     * @param minY the Y coordinate of the upper-left corner
     * @param minZ the minimum z coordinate of the {@code BoundingBox}
     * @param width the width of the {@code BoundingBox}
     * @param height the height of the {@code BoundingBox}
     * @param depth the depth of the {@code BoundingBox}
     */
    public SimpleAABB(@NamedArg("minX") float minX, @NamedArg("minY") float minY, @NamedArg("minZ") float minZ, @NamedArg("width") float width, @NamedArg("height") float height, @NamedArg("depth") float depth) {
        this.minX = minX;
        this.minY = minY;
        this.minZ = minZ;
        this.width = width;
        this.height = height;
        this.thick = depth;
        this.maxX = minX + width;
        this.maxY = minY + height;
        this.maxZ = minZ + depth;
    }

    public float getWidth() {
        return width;
    }

    public void setWidth(float width) {
        this.width = width;
    }

    public float getHeight() {
        return height;
    }

    public void setHeight(float height) {
        this.height = height;
    }

    public float getDepth() {
        return thick;
    }

    public void setDepth(float depth) {
        this.thick = depth;
    }

    public   float width ,height,thick;


}
